<?php
    include 'init.php';

    //接收相册id
    $id = $_GET['album_id'];

    //查询出当前相册下的所有图片
    $sql = "select id,name,createtime from photo where album_id = '$id'";

    $result = mysql_query($sql);

    if($result && mysql_affected_rows()>0){
        $photo_list = array();

        while($row = mysql_fetch_assoc($result)){
            $photo_list[] = $row;
        }
    
    }

    //var_dump(@$photo_list);

    //查询相册名称用来显示在H3标签中
    $sql = "select name from album where id='$id'";

    $name = mysql_fetch_assoc(mysql_query($sql));
    $album_name = $name['name'];

?>
<!doctype html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Photos</title>
        <style type="text/css">
            #div1{
                width:150px;
                height:150px;
                background:url(./img/upload.jpg) -33px -44px;
            }

            #div2{
                margin-top:5px;
                width:150px;
                height:33px;
                background:url(./img/upload.jpg) -31px -3px;
            }

            .mya{
                display:block;
            }

            #a1{
                width:150px;
                height:150px;
            }
            
            #a2{
                width:150px;
                height:33px;
            }

            #photo_list{
                width:650px;
                height:auto;
                border:1px solid orange;
                padding:5px;
            }
            
        </style>
    </head>
    <body>
        <h3>相册名:<?php echo $album_name; ?></h3><!-- 在这里要显示相册名称 -->
        <div><a href="upload.php?album_id=<?php echo $id ?>">添加相片</a></div>
        <?php if(!empty($photo_list)): //如果有照片就显示出来 ?>

        <div id="photo_list">
        <?php foreach($photo_list as $val): ?>

            <?php
                //从图片名来获取图片路径
                $img_path = './uplods/';
                $img_path .= substr($val['name'],0,4).'/';  //2014
                $img_path .= substr($val['name'],4,2).'/';  //07
                $img_path .= substr($val['name'],6,2).'/';  //29
                $img_path .= $val['name'];  //图片名

            ?>
        
                <div style="display:inline-block">
                    <a href="http://localhost/s13/photos/<?php echo $img_path ?>"><img src="<?php echo $img_path; ?>" width="140" height="140" title="<?php echo $val['name'] ?>"/></a>
                    <br/>
                    <a href="doface.php?album_id=<?php echo $id ?>&id=<?php echo $val['id'] ?>">封面</a>

                </div>
        <?php endforeach; ?>
        </div>

        <?php else: //如果没有照片，就让用户去上传个照片好不好？ ?>
        
        <a id="a1" class="mya" href="upload.php?album_id=<?php echo $id ?>"><div id="div1"></div></a>
            
        <a id="a2" class="mya" href="upload.php?album_id=<?php echo $id ?>"><div id="div2"></div></a>
        
        <?php endif; ?>
    </body>
</html>
